package com.cet.test.mt04.qz1;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: cet-practice
 * @description:
 * @author: 陈恩涛
 * @create: 2023-05-06 17:35
 **/
public class BService {

    public List<Integer> get(List<Integer> ids) {

        if (ids.size() > 100) {
            throw new RuntimeException("一次性最多传入100个id！");
        }

        // 每批10个id
        int batchCount = 10;

        // 计算批处理的次数
        int handleTimes = ids.size() / batchCount;
        if (handleTimes * batchCount != ids.size()) {
            handleTimes += 1;
        }

        AService aService = new AService();

        List<Integer> result = new ArrayList<>();

        for (int i = 0; i < handleTimes; i++) {
            List<Integer> batchList = ids
                .stream()
                .skip((long) i * batchCount)
                .limit(batchCount)
                .collect(Collectors.toList());
            List<Integer> returnList = aService.get(batchList);
            result.addAll(returnList);
        }

        return result;
    }
}
